# LIV DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)

library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)

lagpad   = function(x, k) {
  if (!is.vector(x)) 
    stop('x must be a vector')
  if (!is.numeric(x)) 
    stop('x must be numeric')
  if (!is.numeric(k))
    stop('k must be numeric')
  if (1 != length(k))
    stop('k must be a single number')
  c(rep(NA, k), x)[1 : length(x)] 
}

##### lIV DATA GDP #############
data    = read_excel("liv_data_avr.xlsx")

data$fc_err        = data$fc_erry
data$fc_rev        = data$fc_revy
data$fl            = data$fly
data$f1            = data$f1y
data$f1r           = data$f1ry
data$f2r           = data$f2ry

data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))

save(data, file = "us_liv_rgdp_avr.rda")
clear()

##### LIV DATA CPI #############
data    = read_excel("liv_data_avr.xlsx")

data$fc_err        = data$fc_errpi
data$fc_rev        = data$fc_revpi
data$fl            = data$flpi
data$f1            = data$f1pi
data$f1r           = data$f1rpi
data$f2r           = data$f2rpi

data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))

save(data, file = "us_liv_cpi_avr.rda")
clear()
